package com.ghck.shop.dao;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.ghck.shop.model.ShopFlowWater;

public interface ShopFlowWaterMapper {

	@Insert("insert into t_shop_flow_water"
			+ "(shop_user_id,order_id,user_id,create_time,update_time)"
			+ "values"
			+ "(#{shopUserId},#{orderId},#{userId},now(),now())")
	public Integer saveShopFlowWater(ShopFlowWater shopFlowWater);
	
	
	@Select("select * from t_shop_flow_water where shop_user_id=#{userId} order by update_time desc limit #{start},#{limit}")
	public List<ShopFlowWater> listShopFlowWater(@Param("userId")Integer userId,@Param("start")Integer start,@Param("limit")Integer limit);
	
	@Select("select * from t_shop_flow_water where order_id=#{orderId}")
	public ShopFlowWater findShopFlowWaterByOrderId(Integer orderId);
	
	@Update("update t_shop_flow_water set status=1 where id=#{id}")
	public Integer updateShopFlowWaterComplete(Integer id);
	
	@Select("select sum(t2.total_payee) allMount from t_shop_flow_water t1,order_info t2  "
			+ "where t1.order_id=t2.id and t1.shop_user_id=#{userId} and t1.status=1 and date_format(t1.update_time,'%Y-%m')=date_format(now(),'%Y-%m')")
	public Integer monthShopIncome(Integer userId);
	
	@Select("select sum(t2.total_payee) allMount from t_shop_flow_water t1,order_info t2  "
			+ "where t1.order_id=t2.id and t1.shop_user_id=#{userId} and t1.status=1")
	public Integer allShopIncome(Integer userId);
}
